<?php
require_once('functions.php');

// PAYMENT METHOD FUNCTIONS
function GetPayments(){
	$conn = GetConnection();
	return $results = $conn -> query('SELECT * FROM WSP2012_PaymentMethod');
}

function GetPayment($id){
	$conn= GetConnection();
	$sql = "SELECT * FROM WSP2012_PaymentMethod WHERE payment_id=$id ";
	$results = $conn -> query($sql);
	$row = $results -> fetch_assoc();
	$conn -> close();
	return $row;
}

function SavePayment($row){
	$conn = GetConnection();
	$row2 = EscapeRow($row, $conn);
	$sql = "UPDATE `WSP2012_PaymentMethod` " 
		.	"Set contacts_id='$row2[contacts_id]', address_id='$row2[address_id]', order_id='$row2[order_id]', updated_at='$row2[updated_at]', creditcard='$row2[creditcard]', expdate='$row2[expdate]' "
		.	"WHERE payment_id='$row2[id]' ";
	$results = $conn -> query($sql);
	$error = $conn -> error;
	$conn -> close();
	
	return $error == '' ? true : array('SQL Error' => $error);	
}

function CreatePayment($row){
	$conn = GetConnection();
	$row2 = EscapeRow($row, $conn);
	$sql = "INSERT INTO `WSP2012_PaymentMethod` "
		.		"(payment_id, contacts_id, address_id, order_id, created_at, updated_at, creditcard, expdate) "
		.		"VALUES ('$row2[payment_id]', '$row2[contacts_id]', '$row2[address_id]', '$row2[order_id]', '$row2[created_at]', '$row2[updated_at]', '$row2[creditcard]', '$row2[expdate]') ";
	$results = $conn -> query($sql);
	$error = $conn -> error;
	$conn -> close();	
	
	return $error == '' ? true : array('SQL Error' => $error);
}

function DeletePayment($row, $id){
	$conn = GetConnection();
	$row2 = EscapeRow($row, $conn);
	$sql = "DELETE from WSP2012_PaymentMethod WHERE payment_id= '$row2[id]' ";
	$results = $conn -> query($sql);
	$error = $conn -> error;
	$conn -> close();	
	
	return $error == '' ? true : array('SQL Error' => $error);
}
?>
